<?php
/*
 * emlog 工具箱
 *
 * Author:朦胧中的罪恶
 * Email:Colt.hawkins@gmail.com
 * Blog:http://be-evil.org
 * Version:1.6.3
 */
ob_start();

// 工具箱登录密码,默认为emlog, 采用sha1算法加密
// 图形修改请用浏览器访问emlog工具箱的使用"工具箱密码修改"功能修改
// 手动修改请将下面引号中的sha1码替换为您新密码的sha1码即可
$password = '0b479f744ccde36898d672829b3a9d9db7fbbeda';





/* 程序代码开始 */

// 防止搜索引擎抓取
if (isSearchBot()) {
	header('HTTP/1.1 403 Forbidden');
	die;
}

session_start();


if (get_magic_quotes_gpc()) {
	$_GET = stripslashesDeep($_GET);
	$_POST = stripslashesDeep($_POST);
	$_COOKIE = stripslashesDeep($_COOKIE);
	$_REQUEST = stripslashesDeep($_REQUEST);
}

define('EMLOG_ROOT', dirname(__FILE__));

$action = isset($_GET['action']) ? $_GET['action'] : 'index' ;
$todo = isset($_GET['todo']) ? $_GET['todo'] : '' ;
// 功能表
$actions = array (
	// 工具箱首页
	'index',
	// 显示emlog logo
	'logo',
	// 密码重置
	'resetpassword',
	// 文件权限检测
	'permissioncheck',
	// rss 导入
	'rssimport',
	// 执行SQL
	'sqlquery',
	// 更换域名
	'changedomain',
	// 时间调整
	'timeadjust',
	// 关闭插件
	'turnoffplugin',
	// 清除垃圾评论
	'cleanspamcomment',
	// 修复数据表
	'repairtables',
	// 修改密码
	'changepassword',
	// 退出登录
	'logout'
);


// 涉及到数据库操作的功能表
$dataOperateActions = array (
	'resetpassword',
	'rssimport',
	'sqlquery',
	'changedomain',
	'timeadjust',
	'cleanspamcomment',
	'repairtables',
	'turnoffplugin'
);

if (!in_array($action, $actions)) {
	error('未知的操作');
}
if ($action != 'logo') {
	// 用户登录认证
	if (!isset($_SESSION['pass']) || empty($_SESSION['pass']) || $_SESSION['pass'] != $password) {
		if (isPost()) {
			$loginPassword = isset($_POST['password']) ? sha1(trim($_POST['password'])) : error('密码错误！');
			if ($loginPassword != $password) {
				error('密码错误！');
			}
			header('location:'. $_SERVER['PHP_SELF']);
			$_SESSION['version'] = intval($_POST['version']);
			$_SESSION['pass'] = $loginPassword;
			ob_flush();
			exit(0);
		} else {
			htmlHeader('用户登录 - emlog工具箱');
			?>
			<form method="post"> 
				<div class="b">
					<p class="title2">工具箱用户登录</p>
					<li>请输入工具箱登录密码</li>
					<li>
						<input type="text" name="password" size="password"/>
					</li>
					<li>
						请选择您使用的emlog版本:<br>
						<select name="version">
							<option value="6">5.0</option>
							<option value="5">4.2</option>
							<option value="4">4.0-4.1</option>
							<option value="3">3.4-3.5</option>
						</select>
					</li>
					<li>
						<input type="submit" value="登录" />
					</li>
				</div>
			</form>
			<?php
			htmlFooter();
			ob_flush();
			exit(0);
		}
	}
}

// 根据功能载入数据库类
if (in_array($action, $dataOperateActions)) {
	if (file_exists(EMLOG_ROOT . '/config.php')) {
		include_once EMLOG_ROOT .'/config.php';
	} else {
		error('emlog配置文件config.php没有找到!');
	}
}

call_user_func($action, $todo);
ob_flush();


// 过滤xml中的非法字符
function strip_invalid_xml_chars2($in) { 
	$out = "";
	$length = strlen($in);
	for ( $i = 0; $i < $length; $i++) {
		$current = ord($in{$i});
		if ( ($current == 0x9) || ($current == 0xA) || ($current == 0xD) || (($current >= 0x20) && ($current <= 0xD7FF)) || (($current >= 0xE000) && ($current <= 0xFFFD)) || (($current >= 0x10000) && ($current <= 0x10FFFF))) {
			$out .= chr($current);
		} else {
			$out .= " ";
		}
	}
	return $out;
}

function cleanspamcomment() {
	if (isPost()) {
		$db = MySql::getInstance();
		$clean_type = isset($_POST['clean_type']) ? intval($_POST['clean_type']) : 1;
		$use_id = isset($_POST['use_id']) ? intval($_POST['use_id']) : 0;
		$start_id = isset($_POST['start_id']) ? intval($_POST['start_id']) : 0;
		$end_id = isset($_POST['end_id']) ? intval($_POST['end_id']) : 0;
		$conditions = ' hide = \''. ($clean_type == 1 ? 'y' : 'n').'\'';
		$include_posters = isset($_POST['include_posters']) ? intval($_POST['include_posters']) : 0;
		$include_ips = isset($_POST['include_ips']) ? intval($_POST['include_ips']) : 0;
		$include_emails = isset($_POST['include_emails']) ? intval($_POST['include_emails']) : 0;
		$include_urls = isset($_POST['include_urls']) ? intval($_POST['include_urls']) : 0;
		
		$conditions = '';
		if ($include_posters) {
			$posters = isset($_POST['posters']) ? $_POST['posters'] : '';
			if ($posters) {
				$posters = explode(chr(10), $posters);
				foreach ($posters as $data) {
					$data = addslashes($data);
					if ($conditions)
						$conditions .= " OR poster = '$data' ";
					else
						$conditions .= " poster = '$data' ";
				}
			}
		}
		
		if ($include_ips) {
			$ips = isset($_POST['ips']) ? $_POST['ips'] : '';
			if ($ips) {
				$ips = explode(chr(10), $ips);
				foreach ($ips as $data) {
					$data = addslashes($data);
					if ($conditions)
						$conditions .= " OR ip = '$data' ";
					else
						$conditions .= " ip = '$data' ";
				}
			}
		}


		if ($include_emails) {
			$emails = isset($_POST['emails']) ? $_POST['emails'] : '';
			if ($emails) {
				$emails = explode(chr(10), $emails);
				foreach ($emails as $data) {
					$data = addslashes($data);
					if ($conditions)
						$conditions .= " OR mail = '$data' ";
					else
						$conditions .= " mail = '$data' ";
				}
			}
		}

		if ($include_urls) {
			$urls = isset($_POST['urls']) ? $_POST['urls'] : '';
			if ($urls) {
				$urls = explode(chr(10), $urls);
				foreach ($urls as $data) {
					$data = addslashes($data);
					if ($conditions)
						$conditions .= " OR url = '$data' ";
					else
						$conditions .= " url = '$data' ";
				}
			}
		}
		
		if ($use_id && $start_id > 0 && $end_id > 0) {
			if ($start_id > $end_id) {
				$tmp = $end_id;
				$end_id = $start_id;
				$start_id = $end_id;
			}
			if ($conditions)
				$conditions .= ' AND cid >'. $start_id .' AND cid < '. $end_id;
			else
				$conditions .= ' cid >'. $start_id .' AND cid < '. $end_id;
		}
		
		$sql = 'DELETE from '.DB_PREFIX.'comment WHERE '. $conditions;
		$db->query($sql);
		success('评论清理成功！');
	} else {
		htmlHeader('清除垃圾评论 - emlog工具箱');
		?>
		<form method="post" action="?action=cleanspamcomment"> 
			<div class="b">
				<p class="title2">清除垃圾评论</p>
			</div>
			<li><font color="red"><b>请注意：清理前请务必备份您的博客数据库！</b></font></li>
			<li>清除未审核的评论<input type="radio" name="clean_type" value="1" checked />&nbsp;清除已审核的评论<input type="radio" name="clean_type" value="0" /></li>
			<li><input type="checkbox" name="include_posters" value="1" onclick="display('posters', this)"	/>清除包含指定用户名的评论</li>
			<li id="posters" style="display:none;">
			每个用户名占一行：<br>
			<textarea rows="10" cols="40" name="posters"></textarea>
			</li>
			<li><input type="checkbox" name="include_ips" value="1" onclick="display('ips', this)"	/>清除包含指定IP地址的评论</li>
			<li id="ips" style="display:none;">
			每个IP地址占一行：<br>
			<textarea rows="10" cols="40" name="ips"></textarea>
			</li>
			<li><input type="checkbox" name="include_emails" value="1" onclick="display('emails', this)"	/>清除包含指定email地址的评论</li>
			<li id="emails" style="display:none;">
			每个email地址占一行：<br>
			<textarea rows="10" cols="40" name="emails"></textarea>
			</li>
			<li><input type="checkbox" name="include_urls" value="1" onclick="display('urls', this)"	/>清除包含指定主页地址的评论</li>
			<li id="urls" style="display:none;">
			每个主页地址占一行：<br>
			<textarea rows="10" cols="40" name="urls"></textarea>
			</li>
			<li><input type="checkbox" name="use_id" value="1" />只清理指定评论id区间的评论：</li>
			<li>开始id:&nbsp;<input type="text" size="5" name="start_id" /> - 结束id:&nbsp;<input type="text" name="end_id" size="5" />&nbsp;
			<a href="javascript:;" onclick="document.getElementById('find_id').style.display = 'block';this.onclick =function(){};">如何查找开始id和结束id?</a></li> 
			<li id="find_id" style="display:none;">
				请访问后台评论管理页面，直接点击<b>时间最新</b>的一个垃圾评论查看内容，点开后，
				您就可以在浏览器地址栏的url中看到类似http://xxx/admin/comment.php?action=reply_comment&cid=1158这样的地址，
				请记住cid=后面的号码，这个就是<b>结束id</b>。
				然后请回到留言页面向前翻页去寻找<b>时间最早</b>的那个垃圾评论的id，该ID为<b>开始id</b>.两个id号都找到后，请在上面填写您找到的开始id和结束id进行清理。
				请注意本功能也会清除掉两个id区间中的非垃圾留言，所以建议您将不需要删除的评论设置为审核（选择清除未审核的评论时）或非审核状态（选择清除已审核的评论时）以避免被程序清除.</li>
			<li>
				<input type="submit" value="开始清除" />
			</li>
		</form>
		<script type="text/javascript">
		function display(id, checkbox) {
			var ele = document.getElementById(id);
			if (checkbox.checked) {
				ele.style.display = 'block';
			} else {
				ele.style.display = 'none';
			}
		}
		</script>
		<?php
	}
}

// 退出登录
function logout() {
	unset($_SESSION['pass']);
	header('Location:'. $_SERVER['PHP_SELF']);
	ob_flush();
	die();
}

// 修改密码
function changepassword() {
	if (isPost()) {
		$password = isset($_POST['password']) ? trim($_POST['password']) : error('清填写新密码！');
		$password2 = isset($_POST['password2']) ? trim($_POST['password2']) : error('新密码不匹配！');
		if ($password == $password2 && preg_match('/^\w+$/', $password)) {
			if (is_writable(__FILE__)) {
				$_SESSION['pass'] = sha1($password);
				$appContent = file_get_contents(__FILE__);
				$appContent = preg_replace_callback('/\$password\s*=\s*\'(.+?)\';/', 'changePass', $appContent);
				// 更新密码并进入登录状态
				file_put_contents(__FILE__, $appContent);
				header('location:'. $_SERVER['PHP_SELF']);
				success('密码修改成功！');
			} else {
				error('emlog工具箱文件不可写！无法更新工具箱密码');
			}
		} else {
			error('两个输入的密码不匹配或者密码格式不符合要求!');
		}
	} else {
		htmlHeader('密码更新 - emlog工具箱');
		$is_writable = is_writable(__FILE__);
		?>
		<form method="post" action="?action=changepassword"> 
			<div class="b">
				<p class="title2">工具箱密码更新</p>
				<li>您可以在这里直接输入新密码，也可以修改emlog工具箱的程序文件来修改密码.</li>
				<li>请注意：在这里修改工具箱密码需要您给与本程序文件写入权限.<br>
				当前程序文件写入权限状态为：<?php echo is_writable(__FILE__) ? '<font color="green">可写入</font>' : '<font color="red">不可写入</font>'; ?> </li>
				<li>请输入新的登录密码(密码只能由字母、数字构成)</li>
				<li>
					<input type="text" name="password" size="password" <?php !$is_writable && print 'disabled' ?>/>
				</li>
				<li>新密码确认</li>
				<li>
					<input type="text" name="password2" size="password2" <?php !$is_writable && print 'disabled' ?>/>
				</li>
				<li>
					<input type="submit" value="更新密码" <?php !$is_writable && print 'disabled' ?>/>
				</li>
			</div>
		</form>
		<?php
		htmlFooter();
	}
}

function repairtables() {
	if (isPost()) {
		$db = MySql::getInstance();
		$query = $db->query('SHOW TABLES LIKE \'' . DB_PREFIX .'%\'');
		while ($table = $db->fetch_array($query)) {
			$sql = 'REPAIR TABLE `' . $table[0] .'`';
			$db->query('REPAIR TABLE `' . $table[0] .'`');
		}
		success('所有数据表修复完成！');
	} else {
		htmlHeader('数据表修复 - emlog工具箱');
		?>
		<form method="post" action="?action=repairtables">
			<div class="b">
				<p class="title2">修复数据表</p>
				<li>
					如果您的博客访问出现SQL错误提示，内容有"try to repair it"字样，说明您的数据库表需要修复<br />
					本功能可以一键修复emlog数据库中所有出错的数据表,免除复杂的数据库修复操作
				</li>
				<li>
					<input type="submit" value="点击自动修复所有出现问题的表" />
				</li>
			</div>
		</form>
		<?php
		htmlFooter();		
	}
}

function turnoffplugin() {
	if (isPost()) {
		$db = MySql::getInstance();
		$sql = 'UPDATE '. DB_PREFIX .'options SET option_value = \'a:0:{}\' WHERE option_name = \'active_plugins\'';
		$db->query($sql);
		$optionsCacheFile = '';
		if ($_SESSION['version'] >= 5) {
			$optionsCacheFile = 'content/cache/options.php';
		}
		if ($_SESSION['version'] < 5) {
			$optionsCacheFile = 'content/cache/options';
		}
		
		if (is_file($optionsCacheFile) && is_writable($optionsCacheFile)) {
			unlink($optionsCacheFile);
			success('所有插件已关闭！');
		} else {
			error("缓存文件$optionsCacheFile没有写入权限！");
		}
	} else {
		htmlHeader('关闭所有插件 - emlog工具箱');
		?>
		<form method="post"> 
			<div class="b">
				<p class="title2">关闭所有插件</p>
				<li>如果您的emlog在安装或使用插件时出现异常，这里可以一次关闭emlog的所有插件，让博客运行于无插件状态。</li>
				<li>
					<input type="submit" value="关闭所有启用中的插件" />
				</li>
			</div>
		</form>
		<?php
		htmlFooter();
	}
}

function timeadjust() {
	if (isPost()) {
		$intervaldecrease = isset($_POST['intervaldecrease']) ? intval($_POST['intervaldecrease']) : 0;
		$intervaladd = isset($_POST['intervaladd']) ? intval($_POST['intervaladd']) : 0;
		$timeinterval = 0;
		if (empty($intervaldecrease) && empty($intervaladd)) {
			error('请填写一个时间间隔');
		} elseif (!empty($intervaldecrease) && $intervaldecrease > 0) {
			$timeinterval = $intervaldecrease * -3600;
		} elseif (!empty($intervaladd) && $intervaladd > 0) {
			$timeinterval = $intervaladd * 3600;
		} else {
			error('时间调整间隔必须大于0!');
		}
		$db = MySql::getInstance();
		$sql = 'UPDATE '. DB_PREFIX ."attachment SET addtime = addtime + $timeinterval";
		$db->query($sql);
		$sql = 'UPDATE '. DB_PREFIX ."blog SET date = date + $timeinterval";
		$db->query($sql);
		$sql = 'UPDATE '. DB_PREFIX ."comment SET date = date + $timeinterval";
		$db->query($sql);
		$sql = 'UPDATE '. DB_PREFIX ."trackback SET date = date + $timeinterval";
		$db->query($sql);
		$sql = 'UPDATE '. DB_PREFIX ."twitter SET date = date + $timeinterval";
		$db->query($sql);
		success('时间调整完成!');
	} else {
		htmlHeader('Blog时间调整 - emlog工具箱');
		?>
		<form method="post"> 
		<div class="b">
			<p class="title2">Blog时间调整 - <a href="<?php echo $_SERVER['PHP_SELF']?>">&lt;返回首页</a></p>
			<li>
				本功能用于调整emlog中所有记录(日志,评论,碎语,附件)的时间<br>
				如果你的blog时间出现偏差可以使用本功能来快速调整
			</li>
			<li>
				我的Blog显示的时间多了<input type="text" name="intervaldecrease" size="1"/>小时，或者少了<input type="text" name="intervaladd" size="1"/>小时
			</li>
			<li>
				<input type="submit" value="调整时间" />
			</li>
		</div>
		</form>
		<?php
		htmlFooter();
	}	
}

function rssimport() {

	if (isPost()) {
		// 增加程序的最大执行时间
		ini_set('max_execution_time','600');
		$blogtype = $_POST['blogtype'];
		$rssurl = $_POST['rssurl'];
		$items = array();
		$rss = new rss_php;
		if (isset($_FILES['rssfile'])) {
			// 上传时出现错误
			if ($_FILES['rssfile']['error'] != UPLOAD_ERR_OK) {
				switch ($_FILES['rssfile']['error']) {
					case UPLOAD_ERR_INI_SIZE:
						error('您上传xml文件的体积超过了php.ini规定的大小，文件上传失败!');
					break;
					case UPLOAD_ERR_FORM_SIZE:
						
					break;
					case UPLOAD_ERR_CANT_WRITE:
						error('服务器php上传文件零时目录不可写，文件上传失败！');
					break;
					case UPLOAD_ERR_NO_FILE :
						error('没有找到任何上传的文件，文件上传失败！');
					break;
					case UPLOAD_ERR_NO_TMP_DIR:
						error('服务器没有配置php文件上传临时目录，文件上传失败！');
					break;
				}
			}
			$xmlcontents = file_get_contents($_FILES['rssfile']['tmp_name']);
			if (empty($xmlcontents)) {
				error('上传的内容为空');
			}
			$xmlcontents = strip_invalid_xml_chars2($xmlcontents);
			$rss->loadRSS($xmlcontents);
			$items = $rss->getItems();
			if (empty($items)) {
				error('RSS数据未读取到!');
			}
		} elseif (!empty($rssurl)) {
			if (!preg_match('/https?:\/\/([\w-]+\.)+[\w-]+(\/[\w\-.\/?%&=]*)?/i', $rssurl)) {
				error('RSS地址格式不正确');
			}			
			$rss->loadFromUrl($rssurl);
			$items = $rss->getItems();
			if (empty($items)) {
				error('RSS数据未读取到!');
			}
		}
		$db = MySql::getInstance(); 
		// 分类缓存   
		$categorycache = array();
		$query = $db->query('SELECT sid,sortname FROM ' . DB_PREFIX .'sort');
		while ($row = $db->fetch_array($query)) {
			$categorycache[$row['sid']] = $row['sortname'];
		}
		// 用户缓存
		$usercache = array();
		$query = $db->query('SELECT uid,username FROM ' . DB_PREFIX .'user');
		while ($row = $db->fetch_array($query)) {
			$usercache[$row['uid']] = $row['username'];
		}
		
		$foreignblogapp = array('wordpress','Movable Type', 'Typecho');
		
		$sql = $title = $content = $excerpt = $sortid = $date = $author = '';
		$importcount = 0;
		foreach ($items as $key => $item) {
			// 标题
			if (isset($item['title'])) {
				$title = addslashes($item['title']);
			}
			// 内容
			if (isset($item['description'])) {
				$content = addslashes($item['description']);
			}
			// 针对 wordpress RSS的处理
			if (in_array($blogtype, $foreignblogapp)) {
				// 摘要
				if (isset($item['description'])) {
					$excerpt = addslashes($item['description']);
				}
				// 内容
				if (isset($item['content:encoded'])) {
					$content = addslashes($item['content:encoded']);
				}
			}
			
			// 分类
			$sortid = -1;
			if (isset($item['category'])) {
				// 多个分类默认取第一个
				if (is_array($item['category'])) {
					$category = $item['category'][0];
				}
				
				if (is_string($item['category'])) {
					$category = $item['category'];
				}
				// 判断该分类是否已经添加了
				if (in_array($category, $categorycache)) {
					$sortid = array_search($category, $categorycache);
					if (empty($sortid)) {
					   $sortid = -1; 
					}
				} else {
					// 自动增加分类
					$sql = 'INSERT INTO '. DB_PREFIX ."sort (sortname,taxis) VALUES ('$category',0)";
					$db->query($sql);
					$tmpid = (string) $db->insert_id();
					// 增加到分类缓存中
					$categorycache[$tmpid] = $category;
					$sortid = $tmpid;
				}
			}
			// 发布时间
			if (isset($item['pubDate'])) {
			   $date = strtotime($item['pubDate']); 
			}
			// 发布人
			if (isset($item['author'])) {
				if (in_array($item['author'], $usercache)) {
					$author = array_search($item['author'], $usercache);
				} else {
					$useid = array_keys($usercache);
					$author = $useid[0];
				}
			} else {
				$useid = array_keys($usercache);
				$author = $useid[0];
			}
			$sql = 'INSERT INTO '. DB_PREFIX . "blog (title, date, content, excerpt, author, sortid, type, views, comnum, tbcount, attnum, top, hide, allow_remark, allow_tb, password) VALUES ('$title', '$date', '$content', '$excerpt', $author, $sortid,'blog',0,0,0,0,'n','n','y','y','')";
			$db->query($sql);
			$importcount++;
		}
		success("$importcount 条日志被成功导入!<br>请到emlog后台更新缓存!");
	} else {
		htmlHeader('RSS数据导入 - emlog工具箱');
		?>
		<form method="post" enctype="multipart/form-data"> 
		<div class="b">
			<p class="title2">RSS数据导入 - <a href="<?php echo $_SERVER['PHP_SELF']?>">&lt;返回首页</a></p>
			<li>
				博客RSS地址：<input type="text" name="rssurl" size="50"/>
			</li>
			<li>
				上传博客RSS-XML文件：<input type="file" name="rssfile"/><br><font color="red">服务器文件上传大小限制:<?php echo ini_get('upload_max_filesize') ?></font>
			</li>
			<li>
				博客类型:<select name="blogtype">
							<option value="wordpress">wordpress</option>
							<option value="Movable Type">Movable Type</option>
							<option value="Typecho">Typecho</option>
							<option value="other">其他</option>
						 </select>
			</li>
			<li>
				<input type="submit" value="开始导入" />(请在导入前务必备份博客的数据库)
			</li>
			<li>
				部分blog程序RSS输出设置说明<br>
				1. <b>wordpress</b><br>
				后台 - 阅读 - Feeds<br>
				Feed同步最新 -> 设定数值大于当前blog日志总数即可<br>
				Feed中每篇文章，显示 ->  全部文字<br>
	
				2. <b>bo-blog</b><br>
				后台 - 常规管理 - 参数设置 - RSS设置<br>
				RSS最大输出日志数 -> 设定数值大于当前blog日志总数即可<br>
				RSS输出->    RSS中输出全文<br>
	
				3. <b>typecho</b><br>
				编辑 ./var/Widget/Archive.php 第48行 $this->parameter->pageSize = 10; 将10增加大为超过当前blog日志总数即可<br>
	
				4. <b>sablog</b><br>
				系统设置 - RSS 订阅设置 - RSS 订阅文章数量 -> 设定数值大于当前blog日志总数即可<br>	
			</li>
		</div>
		</form>
		<?php
		htmlFooter();
	}
}

function changedomain() {
	if (isPost()) {
		$olddomain = trim($_POST['olddomain']);
		$newdomain = trim($_POST['newdomain']);
		if (!preg_match('/https?:\/\/([\w-]+\.)+[\w-]+(\/[\w\-.\/?%&=]*)?/i', $olddomain))
			error('原博客地址格式不正确');
		if (!preg_match('/https?:\/\/([\w-]+\.)+[\w-]+(\/[\w\-.\/?%&=]*)?/i', $newdomain))
			error('当前博客地址格式不正确');
		
		// 去除地址最后的 /
		if (substr($olddomain, strlen($olddomain) - 1, 1) == '/')
			$olddomain = strtolower(substr($olddomain, 0, strlen($olddomain) - 1));
		if (substr($newdomain, strlen($newdomain) - 1, 1) == '/')
			$newdomain = strtolower(substr($newdomain, 0, strlen($newdomain) - 1));        
		$sql = 'UPDATE '. DB_PREFIX . "blog SET content = replace(content,'$olddomain','$newdomain'), excerpt = replace(excerpt,'$olddomain','$newdomain')";
		$db = MySql::getInstance();
		$db->query($sql);
		$sql = 'UPDATE '. DB_PREFIX . "options SET option_value = '$newdomain' WHERE option_name = 'blogurl'";
		$db->query($sql);
		success('博客地址更换成功!');
	} else {
		htmlHeader('博客日志链接域名更换 - emlog工具箱');
		?>
		<form method="post"> 
		<div class="b">
			<p class="title2">博客日志链接域名更换 - <a href="<?php echo $_SERVER['PHP_SELF']?>">&lt;返回首页</a></p>
			<li>
				原Blog地址：<input type="text" name="olddomain" /><br>
				(请按照http://www.emlog.net格式填写，如果你原地址是在二级目录，那么在url中请包含二级目录)
			</li>
			<li>
				当前Blog地址：<input type="text" name="newdomain" />
			</li>
			<li>
				<input type="submit" value="开始更换" />(请在更换前务必备份blog的数据库)
			</li>
		</div>
		</form>
		<?php
		htmlFooter();
	}
}

function sqlquery() {
	if (isPost()) {
		$sql = $_POST['sql'];
		if (empty($sql))
			error('SQL语句不能为空!');
		MySql::getInstance()->query($sql);
		success('SQL语句运行成功!');
	} else {
		htmlHeader('运行SQL语句 - emlog工具箱');
		?> 
		<form method="post"> 
		<div class="b">
			<p class="title2">运行SQL语句 - <a href="<?php echo $_SERVER['PHP_SELF']?>">&lt;返回首页</a></p>
			<textarea cols="70" rows="10" name="sql"></textarea>
			<input type="submit" value="提交语句" /> (请注意:每次只能执行一条语句)
		</div>
		</form>
		<?php
		htmlFooter();
	}
}


function permissioncheck() {
	htmlHeader('文件权限检测 - emlog工具箱');
	$safe_mode = ini_get('safe_mode');
	?>
	<div class="b">
		<p class="title2">文件权限检测 - <a href="<?php echo $_SERVER['PHP_SELF']?>">&lt;返回首页</a></p>
		<?php if ($safe_mode):?>
		<p><font color="red">提示：您当前主机PHP开启了安全模式(<a href="http://cn.php.net/manual/zh/features.safe-mode.functions.php" target="_black">Safe Mode</a>)，在该模式下emlog相关功能受到了限制，即使下列目录可写emlog也无法上传文件！</font></p>
		<?php endif;?>
		<li>./config.php <?php echo is_writable(EMLOG_ROOT . '/config.php') ? '<font color="green">可写</font>' : '<font color="red">不可写</font>'?></li>
		<li>./content/cache <?php echo is_writable(EMLOG_ROOT . '/content/cache') ? '<font color="green">可写</font>' : '<font color="red">不可写</font>'?></li>
		<li>./content/uploadfile <?php echo is_writable(EMLOG_ROOT . '/content/uploadfile') ? '<font color="green">可写</font>' : '<font color="red">不可写</font>'?></li>
		<li>./content/backup <?php echo is_writable(EMLOG_ROOT . '/content/backup') ? '<font color="green">可写</font>' : '<font color="red">不可写</font>'?></li>
	</div>
	<?php
	htmlFooter();
}

function resetpassword() {
	if (isPost()) {
		$db = MySql::getInstance();
		$username = isset($_POST['username']) ? addslashes(trim($_POST['username'])) : '';
		$password = isset($_POST['password']) ? addslashes(trim($_POST['password'])) : '';
		$password2 = isset($_POST['password2']) ? addslashes(trim($_POST['password2'])) : '';
		if (empty($username)) {
			error('用户名不能为空');
		} else {
			$user = $db->once_fetch_array('SELECT * FROM '. DB_PREFIX .'user WHERE username = \''. $username .'\'');
			if (empty($user))
				error('您输入用户不存在!');
		}
		
		if (preg_match('/^\w{6,20}$/', $password) && $password == $password2) {
			if ($_SESSION['version'] >= 4)
				include EMLOG_ROOT . '/include/lib/passwordhash.php';
			else
				include EMLOG_ROOT . '/lib/class.phpass.php';
			// 实例化密码加密对象
			$PHPASS = new PasswordHash(8, true);
			$newpass = $PHPASS->HashPassword($password);
			$sql = "UPDATE ". DB_PREFIX ."user SET password = '$newpass' WHERE username = '$username' ";
			$db->query($sql);
			success('密码更新成功');
		} else {
			error('您输入的新密码不符合系统要求!');
		}
	} else {
		htmlHeader('管理员密码重设 - emlog工具箱 ');
		?>
		<form method="post">
		<div class="b">
			<p class="title2">管理员密码重设  - <a href="<?php echo $_SERVER['PHP_SELF']?>">&lt;返回首页</a></p>
			<li>
				用户名：<input type="text" name="username" />（该用户名必须存在）
			</li>
			<li>
				新密码：<input type="password" name="password" />
			</li>
			<li>
				新密码确认：<input type="password" name="password2" />
			</li>
			<li>
				<input type="submit" value="重设密码" />
			</li>
		</div>
		</form>
		<?php
		htmlFooter();
	}
}


function index($todo) {
	htmlHeader('emlog工具箱');
	if ($todo == ''):
	?>
	<div class="b">
	<p class="title2">工具列表</p>
		<li>
			<a href='<?php echo $_SERVER['PHP_SELF']?>?action=permissioncheck'>&middot; Blog文件权限检测</a>
		</li>
		<li>
			<a href='<?php echo $_SERVER['PHP_SELF']?>?action=resetpassword'>&middot; 重置管理员密码</a>
		</li>
		<li>
			<a href='<?php echo $_SERVER['PHP_SELF']?>?action=sqlquery'>&middot; 运行SQL语句</a>
		</li>
		<li>
			<a href='<?php echo $_SERVER['PHP_SELF']?>?action=changedomain'>&middot; Blog域名更换</a>
		</li>
		<li>
			<a href='<?php echo $_SERVER['PHP_SELF']?>?action=rssimport'>&middot; RSS数据导入</a>
		</li>
		<li>
			<a href='<?php echo $_SERVER['PHP_SELF']?>?action=timeadjust'>&middot; Blog时间调整</a>
		</li>
		<li>
			<a href='<?php echo $_SERVER['PHP_SELF']?>?action=turnoffplugin'>&middot; 关闭所有插件</a>
		</li>
		<li>
			<a href='<?php echo $_SERVER['PHP_SELF']?>?action=cleanspamcomment'>&middot; 清除垃圾评论</a>
		</li>
		<li>
			<a href='<?php echo $_SERVER['PHP_SELF']?>?action=repairtables'>&middot; 修复数据表</a>
		</li>
		<li>
			<a href='<?php echo $_SERVER['PHP_SELF']?>?action=changepassword'>&middot; 工具箱密码修改</a>
		</li>
		<li>
			<a href='<?php echo $_SERVER['PHP_SELF']?>?action=logout'>&middot; 退出登录</a>
		</li>
	</div>
	<?php
	endif;
	htmlFooter();
}

/** 核心函数区 **/

function logo() {
	Header('Content-type: image/png');
	echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAALwAAACHCAIAAAAjlqSSAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAR/dJREFUeNrsvWewZdd1JrbDiTe93DkBHYHuRiQIgAgEEwiRNANMWdSQnJkyR/aU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P/xhgJkXX3wRyC8cALIF9rkND8EemhN54sSJyclJ6n4wfNhCdI/CzOPj4zfeeCPc5amnnvrYxz5GghKYjfJGSBPBKRRyAS51KRIz8Ai/h4a3DVICkAAdsYtvkSeGmdUnAEVgPxHkYiVOOhL4MpV+gu5nJsZE1d1JdMBEt9MJYCdWvjEgNDU1BbcD5IDTYScwYhBEsPbtQjjAkOCmVB+IKBGuiTQ9TRMqLmkK4kBofuVEuG86Hwxr6A8rE33ZPxQcsDttHj4xCVqYwh5PTjlbcbIoo7az7eyiYtI0K0TdF8eurYivUOxoIDS/DqRZMmnExo+WTAqw68XZ4uTUhcUskWIM3GYjWc1ow42EH7TCTbFCEXtnKNQeyS5nRbGB9fSeOGnYoplp1G125S1WSGGhlUtZYX4FW8iYJpbDFnIXizNc+6aoFu9I9cJt5VRm1tQhicFabuYne4p1ECw5n2SANL8mIlz0vi8eu4tTF6yTl9xrRT3F3plBUZwp1ne6nbhYhI2+DAeyq+1Oyri1ht5yKVcDoRlsv4JtIDSDbSA0g20gNINtIDSDbSA0g20gNINtsF3K9v8LMADmQ20v2CzlogAAAABJRU5ErkJggg==');
}


function stripslashesDeep($value) {
	$value = is_array($value) ? array_map('stripslashesDeep', $value) : stripslashes($value);
	return $value;
}

function error($errorMessage) {
	htmlHeader($errorMessage);
	echo '<p class="error_message">' . $errorMessage .'</p>';
	echo '<p class="error_message"><a href="javascript:history.go(-1);">返回</a></p>';
	htmlFooter();
	die;
}

function success($successMessage) {
	htmlHeader($successMessage);
	echo '<p class="error_message">' . $successMessage .'</p>';
	echo '<p class="error_message"><a href="'. $_SERVER['PHP_SELF'] .'">返回工具箱首页</a></p>';
	htmlFooter();
	die;
}


function isPost() {
	return $_SERVER['REQUEST_METHOD'] == 'POST';
}

function changePass($matchs) {
	global $password;
	if (isset($matchs[1])) {
		return '$password = \''. $_SESSION['pass'] .'\';'. chr(10);
	} else {
		return '';
	}
}

function htmlHeader($headText) {
?>
<html>
<head>
<meta name="robots" content="noindex,nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $headText?></title>
<style type="text/css">
body {
	background-color: #D4E9EA;
	font-family: Verdana, Tahome, Arial;
	font-size: 12px;
	line-height:150%;
}
a {
	color:#0066CC;
	text-decoration:none;
}
.main {
	background-color:#FFFFFF;
	margin-top:20px;
	font-size: 12px;
	color: #666666;
	width:650px;
	margin:10px auto;
	padding:10px;
	list-style:none;
}
#top-title{
	background:url(<?php echo $_SERVER['PHP_SELF'] . '?action=logo'?>) no-repeat center;
	padding:35px 0px;
	margin:30px 0px 50px 0px;
}
.input {
	border: 1px solid #CCCCCC;
	font-family: Verdana, Tahome, Arial;
	font-size: 18px;
	height:28px;
	background-color:#F7F7F7;
	color: #666666;
	margin:5px 25px;
}
.submit{
	background-color:#FFFFFF;
	border: 3px double #999;
	border-left-color: #ccc;
	border-top-color: #ccc;
	color: #333;
	padding: 0.25em;
	cursor:hand;
}
.title{
	font-size:30px;
	font-weight:bold;
	text-align:left;
	padding-left:40px;
}
.care{
	color:#0066CC;
	padding:0px 10px;
}
.title2{
	font-size:12px;
	color:#666;
	padding-left:20px;
	border-bottom: #CCCCCC 1px solid;
	font-weight:bold;
}
.foot{
	text-align:center;
}
li{
	border-bottom:#CCCCCC 1px dotted;
	margin:20px 20px;
}

.error_message {
	text-align:center;
	font-weight:bold;
	font-size:16px;
}
</style>
</head>
<body>
<div class="main">
<div id="top-title">
<p>&nbsp;</p>
</div>
<?php if (isset($_SESSION['pass']) && $_SESSION['pass'] == 'cff86098ab3525bfdeed6922c60d6f0fb1b067cc'):?>
	<div class="b">
		<p style="text-align:center"><font color="red"><b>注意：您正在使用的是默认密码，为了您空间的安全，请更新工具箱密码！</b></font></p>
	</div>
<?php endif;?>
<?php
}

function htmlFooter() {
?>
<p class="foot">
&copy;2010 emlog
</p>
</div>
</body>
<?php
}

function isSearchBot() {
	$user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
	$identify = array(
		'googlebot',
		'adsbot-google',
		'gsa-crawler',
		'mediapartners-google',
		'baiduspider',
		'yahoo!slurp',
		'inktomi',
		'msnbot',
		'yodaobot',
		'outfoxbot',
		'sogou spider',
		'sosospider',
		'iaskspider',
		'naverrobot'
	);
	foreach ($identify AS $key => $tag) {
		if (strstr($user_agent, $tag)) {
			return true;
		}
	}
	return false;
}


/** 核心类部分 **/
/**
 * MYSQL数据操方法封装类
 */

class MySql {
	/**
	 * 查询次数
	 * @var int
	 */
	private $queryCount = 0;
	/**
	 * 内部数据连接对象
	 * @var resourse
	 */
	private $conn;
	/**
	 * 内部数据结果
	 * @var resourse
	 */
	private $result;
	/**
	 * 内部实例对象
	 * @var object MySql
	 */
	private static $instance = null;

	/**
	 * 构造函数
	 *
	 */
	private function __construct($host = null, $user = null, $pass = null, $name = null, $charset = 'utf8') {
		if (!function_exists('mysql_connect')) {
			error('服务器PHP不支持MySql数据库');
		}
		// 自定义信息链接数据库
		if ($host && $user) {
			if (!$this->conn = @mysql_connect($host, $user, $pass)) {
				error("MySQL 错误:<br>" . $this->geterror());
			}
			if ($this->getMysqlVersion() > '4.1') {
				mysql_query("SET NAMES '$charset'");
			}
			@mysql_select_db($name, $this->conn) OR error("未找到指定数据库");
		} else {// 使用常量链接数据库
			if (!$this->conn = @mysql_connect(DB_HOST, DB_USER, DB_PASSWD)) {
				error("MySQL 错误:<br>" . $this->geterror());
			}
			if ($this->getMysqlVersion() > '4.1') {
				mysql_query("SET NAMES '$charset'");
			}
			@mysql_select_db(DB_NAME, $this->conn) OR error("未找到指定数据库");
		}
	}

	/**
	 * 静态方法，返回数据库连接实例
	 *
	 * @return MySql
	 */
	public static function getInstance($host = null, $user = null, $pass = null, $name = null, $charset = 'utf8') {
		return new MySql($host, $user, $pass, $name, $charset);
	}

	/**
	 * 关闭数据库连接
	 *
	 * @return boolean
	 */
	function close() {
		return mysql_close($this->conn);
	}

	/**
	 * 发送查询语句
	 *
	 * @param string $sql
	 * @return boolean
	 */
	function query($sql) {
		$this->result = @mysql_query($sql, $this->conn);
		$this->queryCount++;
		if (!$this->result) {
			error("SQL语句执行错误：$sql <br />" . $this->geterror());
		}else {
			return $this->result;
		}
	}

	/**
	 * 从结果集中取得一行作为关联数组/数字索引数组
	 *
	 * @param resource $query
	 * @return array
	 */
	function fetch_array($query) {
		return mysql_fetch_array($query);
	}

	function once_fetch_array($sql) {
		$this->result = $this->query($sql);
		return $this->fetch_array($this->result);
	}

	/**
	 * 从结果集中取得一行作为数字索引数组
	 *
	 * @param resource $query
	 * @return integer
	 */
	function fetch_row($query) {
		return mysql_fetch_row($query);
	}

	/**
	 * 取得行的数目
	 *
	 * @param resource $query
	 * @return integer
	 */
	function num_rows($query) {
		return mysql_num_rows($query);
	}

	/**
	 * 取得结果集中字段的数目
	 *
	 * @param resource $query
	 * @return integer
	 */
	function num_fields($query) {
		return mysql_num_fields($query);
	}
	/**
	 * 取得上一步 INSERT 操作产生的 ID
	 *
	 * @return integer
	 */
	function insert_id() {
		return mysql_insert_id($this->conn);
	}

	/**
	 * 获取mysql错误
	 *
	 * @return unknown
	 */
	function geterror() {
		return mysql_error();
	}

	/**
	 * Get number of affected rows in previous MySQL operation
	 *
	 * @return int
	 */
	function affected_rows() {
		return mysql_affected_rows();
	}

	/**
	 * 取得数据库版本信息
	 *
	 * @return string
	 */
	function getMysqlVersion() {
		return mysql_get_server_info();
	}

	/**
	 * 取得数据库查询次数
	 *
	 * @return string
	 */
	function getQueryCount() {
		return $this->queryCount;
	}
}

/*
	RSS_PHP - the PHP DOM based RSS Parser
	Author: <rssphp.net>
	Published: 200801 :: blacknet :: via rssphp.net
	
	RSS_PHP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.

	Usage:
		See the documentation at http://rssphp.net/documentation
	Examples:
		Can be found online at http://rssphp.net/examples
*/

class rss_php {
	
	public $document;
	public $channel;
	public $items;

	# load RSS by URL
		public function loadFromUrl($url = false, $unblock = true) {
			if($url) {
//                if($unblock) {
//                    $this->loadParser(file_get_contents($url, false, $this->randomContext()));
//                } else {
//                    $this->loadParser(file_get_contents($url));
//                }
				$content = '';
				try { 
					// curl 方式
					$http = Http::factory($url, Http::TYPE_CURL); 
					$content = $http->get();
				} catch (Exception $e) { 
					try { 
						// fsockopen 方式
						$http = Http::factory($url, Http::TYPE_SOCK); 
						$content = $http->get();
					} catch (Exception $e) { 
						try { 
							// file_get_contents 方式
							$http = Http::factory($url, Http::TYPE_STREAM); 
							$content = $http->get();
						} catch (Exception $e) { 
							
						}
					}  
				}
				$content = strip_invalid_xml_chars2($content);
				$this->loadParser($content);
			}
		}
		
	# load raw RSS data
		public function loadRSS($rawxml=false) {
			if($rawxml) {
				$this->loadParser($rawxml);
			}
		}
		
	# return full rss array
		public function getRSS($includeAttributes=false) {
			if($includeAttributes) {
				return $this->document;
			}
			return $this->valueReturner();
		}
	# return channel data
		public function getChannel($includeAttributes=false) {
			if($includeAttributes) {
				return $this->channel;
			}
			return $this->valueReturner($this->channel);
		}
	# return rss items
		public function getItems($includeAttributes=false) {
			if($includeAttributes) {
				return $this->items;
			}
			return $this->valueReturner($this->items);
		}


	private function loadParser($rss=false) {
		if($rss) {
			$this->document = array();
			$this->channel = array();
			$this->items = array();
			$DOMDocument = new DOMDocument;
			$DOMDocument->strictErrorChecking = false;
			$DOMDocument->loadXML($rss);
			$this->document = $this->extractDOM($DOMDocument->childNodes);
		}
	}
	
	private function valueReturner($valueBlock=false) {
		if(!$valueBlock) {
			$valueBlock = $this->document;
		}
		foreach($valueBlock as $valueName => $values) {
				if(isset($values['value'])) {
					$values = $values['value'];
				}
				if(is_array($values) && !empty($values)) {
					$valueBlock[$valueName] = $this->valueReturner($values);
				} else {
					$valueBlock[$valueName] = $values;
				}
		}
		return $valueBlock;
	}
	
	private function extractDOM($nodeList,$parentNodeName=false) {
		$itemCounter = 0;
		$tempNode = array();
		foreach($nodeList as $values) {
			if(substr($values->nodeName,0,1) != '#') {
				if($values->nodeName == 'item') {
					$nodeName = $values->nodeName.':'.$itemCounter;
					$itemCounter++;
				} else {
					$nodeName = $values->nodeName;
				}
				if (is_array($tempNode) == false)
					$tempNode = array();
				$tempNode[$nodeName] = array();                
				if($values->attributes) {
					for($i=0;$values->attributes->item($i);$i++) {
						$tempNode[$nodeName]['properties'][$values->attributes->item($i)->nodeName] = $values->attributes->item($i)->nodeValue;
					}
				}
				if(!$values->firstChild) {
					$tempNode[$nodeName]['value'] = $values->textContent;
				} else {
					$tempNode[$nodeName]['value']  = $this->extractDOM($values->childNodes, $values->nodeName);
				}
				if(in_array($parentNodeName, array('channel','rdf:RDF'))) {
					if($values->nodeName == 'item') {
						$this->items[] = $tempNode[$nodeName]['value'];
					} elseif(!in_array($values->nodeName, array('rss','channel'))) {
						$this->channel[$values->nodeName] = $tempNode[$nodeName];
					}
				}
			} elseif(substr($values->nodeName,1) == 'text') {
				$tempValue = trim(preg_replace('/\s\s+/',' ',str_replace("\n",' ', $values->textContent)));
				if($tempValue) {
					$tempNode = $tempValue;
				}
			} elseif(substr($values->nodeName,1) == 'cdata-section'){
				$tempNode = $values->textContent;
			}
		}
		return $tempNode;
	}
	
	private function randomContext() {
		$headerstrings = array();
		$headerstrings['User-Agent'] = 'Mozilla/5.0 (Windows; U; Windows NT 5.'.rand(0,2).'; en-US; rv:1.'.rand(2,9).'.'.rand(0,4).'.'.rand(1,9).') Gecko/2007'.rand(10,12).rand(10,30).' Firefox/2.0.'.rand(0,1).'.'.rand(1,9);
		$headerstrings['Accept-Charset'] = rand(0,1) ? 'en-gb,en;q=0.'.rand(3,8) : 'en-us,en;q=0.'.rand(3,8);
		$headerstrings['Accept-Language'] = 'en-us,en;q=0.'.rand(4,6);
		$setHeaders =     'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'."\r\n".
						'Accept-Charset: '.$headerstrings['Accept-Charset']."\r\n".
						'Accept-Language: '.$headerstrings['Accept-Language']."\r\n".
						'User-Agent: '.$headerstrings['User-Agent']."\r\n";
		$contextOptions = array(
			'http'=>array(
				'method'=>"GET",
				'header'=>$setHeaders
			)
		);
		return stream_context_create($contextOptions);
	}
	
}

/************************************************************ 
  *  描述：HTTP操作类 
  *  作者：heiyeluren 
  *  修改/优化: 朦胧中的罪恶
  *  email:colt.hawkins@gmail.com
  * 
  ************************************************************/  

/** 
 * HTTP功能工厂方法类 
 *
 */  
class Http {  
	/** 
	 * @var 使用 CURL 
	 */  
	const TYPE_CURL   = 1;  
	/** 
	 * @var 使用 Socket 
	 */   
	const TYPE_SOCK   = 2;  
	/** 
	 * @var 使用 Stream 
	 */   
	const TYPE_STREAM  = 3;  
	/**
	 * http 静态实例
	 */
	protected static $_instance = null;

	/** 
	 * 保证对象不被clone 
	 */  
	protected function __clone() {}  

	/** 
	 * 构造函数 
	 */  
	protected function __construct() {}  
   
   
	/** 
	 * HTTP工厂操作方法 
	 * 
	 * @param string $url 需要访问的URL 
	 * @param int $type 需要使用的HTTP类 
	 * @return object 
	 */  
	public static function factory($url = '', $type = self::TYPE_SOCK) {  
		if (self::$_instance instanceof Http_Basic) {
			return self::$_instance;
		}
		if ($type == '') {  
			$type = self::TYPE_SOCK;  
		}
		switch($type) {  
			case self::TYPE_CURL :  
				if (!function_exists('curl_init')) {  
					throw new Exception(__CLASS__ . " PHP CURL extension not install");  
				}  
				self::$_instance = new Http_Curl($url);  
				break;  
			case self::TYPE_SOCK :  
				if (!function_exists('fsockopen')) {  
					throw new Exception(__CLASS__ . " PHP function fsockopen() not support");  
				}      
				self::$_instance = new Http_Sock($url);  
				break;  
			case self::TYPE_STREAM :  
				if (!function_exists('stream_context_create')) {  
					throw new Exception(__CLASS__ . " PHP Stream extension not install");  
				}      
				self::$_instance = new Http_Stream($url);  
				break;  
				default:  
				throw new Exception("http access type $type not support");  
		}  
		return self::$_instance;
	}  
	
	
	/** 
	 * 生成一个供Cookie或HTTP GET Query的字符串 
	 * 
	 * @param array $data 需要生产的数据数组，必须是 Name => Value 结构 
	 * @param string $sep 两个变量值之间分割的字符，缺省是 &  
	 * @return string 返回生成好的Cookie 查询字符串 
	 */  
	public static function makeQuery($data, $sep = '&'){  
		$encoded = '';  
		while (list($k,$v) = each($data)) {   
			$encoded .= ($encoded ? "$sep" : "");  
			$encoded .= rawurlencode($k) ."=". rawurlencode($v);   
		}   
		return $encoded;
	}
}  
   
abstract class Http_Basic {
	/** 
	 * @var object 对象单例 
	 */  
	static $_instance = NULL;  

	/** 
	 * @var string 需要发送的cookie信息 
	 */  
	protected $cookies = '';  
	/** 
	 * @var array 需要发送的头信息 
	 */  
	protected $header = array();  
	/** 
	 * @var string 需要访问的URL地址 
	 */   
	protected $uri = '';  
	/** 
	 * @var array 需要发送的数据 
	 */  
	protected $vars = array(); 
	/** 
	 * 保证对象不被clone 
	 */  
	protected function __clone() {}
	
	/** 
	 * 构造函数 
	 * 
	 * @param string $configFile 配置文件路径 
	 */  
	public function __construct($url) {  
		$this->uri = $url;  
	}  

	/** 
	 * 设置需要发送的HTTP头信息 
	 *  
	 * @param array/string 需要设置的头信息，可以是一个 类似 array('Host: example.com', 'Accept-Language: zh-cn') 的头信息数组 
	 *       或单一的一条类似于 'Host: example.com' 头信息字符串 
	 * @return void 
	 */  
	public function setHeader($header) {  
		if (empty($header)) {  
			return;  
		}
		if (is_array($header)) {  
			foreach ($header as $k => $v){  
				$this->header[] = is_numeric($k) ? trim($v) : (trim($k) .": ". trim($v));      
			}  
		} elseif (is_string($header)) {  
			$this->header[] = $header;  
		}  
	}  
	
	/** 
	* 设置Cookie头信息 
	*  
	* 注意：本函数只能调用一次，下次调用会覆盖上一次的设置 
	* 
	* @param string/array 需要设置的 Cookie信息，一个类似于 'name1=value1&name2=value2' 的Cookie字符串信息， 
	*         或者是一个 array('name1'=& gt;'value1', 'name2'=>'value2') 的一维数组 
	* @return void 
	*/  
	public function setCookie($cookie){  
		if (empty($cookie)) {  
			return;  
		}  
		if (is_array($cookie)) {  
			$this->cookies = Http::makeQuery($cookie, ';');  
		} elseif (is_string($cookie)) {  
			$this->cookies = $cookie;  
		}  
	}  
	
	/** 
	 * 设置要发送的数据信息 
	 * 
	 * 注意：本函数只能调用一次，下次调用会覆盖上一次的设置 
	 * 
	 * @param array 设置需要发送的数据信息，一个类似于 array('name1'=>'value1', 'name2'=>'value2') 的一维数组 
	 * @return void 
	 */  
	public function setVar($vars) {  
		if (empty($vars)) {  
			return;  
		}  
		if (is_array($vars)) {  
			$this->vars = $vars;  
		}   
	}  
	
	/** 
	 * 设置要请求的URL地址 
	 * 
	 * @param string $url 需要设置的URL地址 
	 * @return void 
	 */  
	public function setUrl($url) {  
		if ($url != '') {  
			$this->uri = $url;  
		}  
	}  
	 
   
	/** 
	 * 发送HTTP GET请求 
	 * 
	 * @param string $url 如果初始化对象的时候没有设置或者要设置不同的访问URL，可以传本参数 
	 * @param array $vars 需要单独返送的GET变量 
	 * @param array/string 需要设置的头信息，可以是一个 类似 array('Host: example.com', 'Accept-Language: zh-cn') 的头信息数组 
	 *         或单一的一条类似于 'Host: example.com' 头信息字符串 
	 * @param string/array 需要设置的Cookie信息，一个类似于 'name1=value1&name2=value2' 的Cookie字符串信息， 
	 *         或者是一个 array('name1'=& gt;'value1', 'name2'=>'value2') 的一维数组 
	 * @param int $timeout 连接对方服务器访问超时时间，单位为秒 
	 * @param array $options 当前操作类一些特殊的属性设置 
	 * @return unknown 
	 */  
	public function get($url = '', $vars = array(), $header = array(), $cookie = '', $timeout = 5, $options = array()){  
		$this->setUrl($url);  
		$this->setHeader($header);  
		$this->setCookie($cookie);  
		$this->setVar($vars);  
		return $this->send('GET', $timeout);  
	}   
	
   
	/** 
	 * 发送HTTP POST请求 
	 * 
	 * @param string $url 如果初始化对象的时候没有设置或者要设置不同的访问URL，可以传本参数 
	 * @param array $vars 需要单独返送的GET变量 
	 * @param array/string 需要设置的头信息，可以是一个 类似 array('Host: example.com', 'Accept-Language: zh-cn') 的头信息数组 
	 *         或单一的一条类似于 'Host: example.com' 头信息字符串 
	 * @param string/array 需要设置的Cookie信息，一个类似于 'name1=value1&name2=value2' 的Cookie字符串信息， 
	 *         或者是一个 array('name1'=& gt;'value1', 'name2'=>'value2') 的一维数组 
	 * @param int $timeout 连接对方服务器访问超时时间，单位为秒 
	 * @param array $options 当前操作类一些特殊的属性设置 
	 * @return unknown 
	 */  
	public function post($url = '', $vars = array(), $header = array(), $cookie = '', $timeout = 5, $options = array()) {  
		$this->setUrl($url);  
		$this->setHeader($header);  
		$this->setCookie($cookie);  
		$this->setVar($vars);  
		return $this->send('POST', $timeout);  
	}
	
	protected function unchunkHttp11($data) {
		$fp = 0;
		$outData = '';
		while ($fp < strlen($data)) {
			$rawnum = substr($data, $fp, strpos(substr($data, $fp), "\r\n") + 2);
			$num = hexdec(trim($rawnum));
			$fp += strlen($rawnum);
			$chunk = substr($data, $fp, $num);
			$outData .= $chunk;
			$fp += strlen($chunk);
		}
		return $outData;
	}
}


 
   
   
 /** 
  * 使用CURL 作为核心操作的HTTP访问类 
  * 
  * @desc CURL 以稳定、高效、移植性强作为很重要的HTTP 协议访问客户端，必须在PHP中安装 CURL 扩展才能使用本功能 
  */  
class Http_Curl extends Http_Basic {
	/** 
	 * 发送HTTP请求核心函数 
	 * 
	 * @param string $method 使用GET还是 POST方式访问 
	 * @param array $vars 需要另外附加发送的GET/POST数据 
	 * @param int $timeout 连接对方服务器访问超时时间，单位为秒 
	 * @param array $options 当前操作类一些特殊的属性设置 
	 * @return string 返回服务器端读取的返回数据 
	 */  
	public function send($method = 'GET', $timeout = 5, $options = array()) {  
		// 处理参数是否为空  
		if ($this->uri == '') {  
			throw new Exception(__CLASS__ .": Access url is empty");  
		}  

		// 初始化CURL  
		$ch = curl_init();  
		curl_setopt($ch, CURLOPT_HEADER, 0);  
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);  
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
		curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);  

		// 设置特殊属性  
		if (!empty($options)){  
			curl_setopt_array($ch , $options);  
		}          
		// 处理GET请求参数  
		if ($method == 'GET' && !empty($this->vars)) {  
			$query = Http::makeQuery($this->vars);  
			$parse = parse_url($this->uri);  
			$sep = isset($parse['query'])  ?  '&'  : '?';  
			$this->uri .= $sep . $query;  
		}  
		// 处理POST请求数据  
		if ($method == 'POST'){  
			curl_setopt($ch, CURLOPT_POST, 1 );  
			curl_setopt($ch, CURLOPT_POSTFIELDS, $this->vars);  
		}  

		// 设置cookie信息  
		if (!empty($this->cookies)) {  
			curl_setopt($ch, CURLOPT_COOKIE, $this->cookies);  
		}  
		// 设置HTTP缺省头  
		if (empty($this->header)) {  
			$this->header = array(  
				'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1)',  
				//'Accept-Language: zh-cn',            
				//'Cache-Control: no-cache',  
			);  
		}  
		curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);  
		// 发送请求读取输数据  
		curl_setopt($ch, CURLOPT_URL, $this->uri);          
		$data = curl_exec($ch);  
		if ($err = curl_error($ch)) {  
			curl_close($ch);  
			throw new  Exception(__CLASS__ ." error: ". $err);  
		}  
		curl_close($ch);  
		return $data;  
	}
}  
   
   
   
   
/** 
 * 使用 Socket操作(fsockopen) 作为核心操作的HTTP访问接口 
 * 
 * @desc Network/fsockopen 是PHP 内置的一个Sokcet网络访问接口，必须安装/打开 fsockopen 函数本类才能工作， 
 *    同时确保其他相关网络环境和配置是正确的 
 */  
class Http_Sock extends Http_Basic {
	/** 
	 * 发送HTTP请求核心函数 
	 * 
	 * @param string $method 使用GET还是 POST方式访问 
	 * @param array $vars 需要另外附加发送的GET/POST数据 
	 * @param int $timeout 连接对方服务器访问超时时间，单位为秒 
	 * @param array $options 当前操作类一些特殊的属性设置 
	 * @return string 返回服务器端读取的返回数据 
	 */  
	public function send($method = 'GET', $timeout = 5, $options = array()) {  
		//处理参数是否为空  
		if ($this->uri == ''){  
			throw new Exception(__CLASS__ .": Access url is empty");  
		}  

		// 处理GET请求参数  
		if ($method == 'GET' && !empty($this->vars)){  
			$query = Http::makeQuery($this->vars);  
			$parse = parse_url($this->uri);  
			$sep = isset($parse['query'])&&($parse['query']!='')  ?  '&'  : '?';  
			$this->uri .= $sep . $query;  
		}  

		// 处理POST请求数据  
		$data = '';  
		if ($method == 'POST' && !empty($this->vars)){  
			$data = Http::makeQuery($this->vars);  
			$this->setHeader('Content-Type: application/x-www-form-urlencoded');    
			$this->setHeader('Content-Length: '. strlen($data));  
		}  

		//解析URL地址  
		$url = parse_url($this->uri);  
		$host = $url['host'];  
		$port = isset($url['port']) && ($url['port']!='') ? $url['port'] : 80;  
		$path = isset($url['path']) && ($url['path']!='') ? $url['path'] : '/';  
		$path .= isset($url['query']) ? "?". $url['query'] : '';  

		// 组织HTTP请求头信息  
		array_unshift($this->header, $method ." ". $path ." HTTP/1.1");  
		$this->setHeader('User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1)');  
		if (!preg_match("/^[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}$/", $host)) {  
			$this->setHeader("Host: ".$host);  
		}  
		if ($this->cookies != ''){  
			$this->setHeader("Cookie: ". $this->cookies);  
		}
		$this->setHeader("Connection: keep-alive");  
		//'Accept-Language: zh-cn',  
		//'Cache-Control: no-cache',  

		// 构造请求信息  
		$header = '';  
		foreach ($this->header as $h) {  
			$header .= $h ."\r\n";  
		}  
		$header .= "\r\n";  
		if ($method == 'POST' && $data != ''){  
			$header .= $data ."\r\n";  
		}  

		// 连接服务器发送请求数据  
		$ip = gethostbyname($host);  
		if (!($fp = fsockopen($ip, $port, $errno, $errstr, $timeout))){  
			throw new Exception(__CLASS__ .": Can't connect $host:$port, errno:$errno,message:$errstr");  
		}  

		fputs($fp, $header);  
		$lineSize = 1024;    

		// 处理301,302跳转页面访问  
		$line = fgets($fp, $lineSize);  
		$first = preg_split("/\s/", trim($line));  
		if ( isset($first[1]) && in_array($first[1], array('301','302')) ){  
			while (!feof($fp)) {     
				$line = fgets($fp, $lineSize);  
				$second = preg_split("/\s/", trim($line));  
				if (ucfirst(trim($second[0]))=='Location:' && $second[1]!='') {  
					$this->header = array();  
					return $this->get(trim($second[1]));  
				}  
			}  
		}  

		$response = '';
		while (!feof($fp)) {
			$response .= fgets($fp, 1160);
		}
		
		die($response);
		// 取内容
		$data = substr($response, (strpos($response, "\r\n\r\n") + 4));
		// 处理分块传输的数据
		if (strpos(strtolower($response), 'transfer-encoding: chunked') !== FALSE) {
			$data = $this->unchunkHttp11($data);
		}
		fclose($fp);
		return $data;   
	}
}  
   

/** 
 * 使用文件流操作函数为核心操作的HTTP访问接口 
 * 
 * @desc stream_* 和 fopen/file_get_contents 是 PHP内置的一个流和文件操作接口，必须打开 fsockopen 函数本类才能工作， 
 *    同时确保其他相关网络环境和配置是正确的，包括 allow_url_fopen 等设置 
 */  
class Http_Stream extends Http_Basic {
	/** 
	 * 发送HTTP请求核心函数 
	 * 
	 * @param string $method 使用GET还是 POST方式访问 
	 * @param array $vars 需要另外附加发送的GET/POST数据 
	 * @param int $timeout 连接对方服务器访问超时时间，单位为秒 
	 * @param array $options 当前操作类一些特殊的属性设置 
	 * @return string 返回服务器端读取的返回数据 
	 */  
	public function send($method = 'GET', $timeout = 5, $options = array()){  
		// 处理参数是否为空  
		if ($this->uri == ''){  
			throw new Exception(__CLASS__ .": Access url is empty");  
		}  
		$parse = parse_url($this->uri);  
		$host = $parse['host'];  

		// 处理GET请求参数  
		if ($method == 'GET' && !empty($this->vars)){  
			$query = Http::makeQuery($this->vars);  
			$sep = isset($parse['query'])&&($parse['query']!='')  ?  '&'  : '?';  
			$this->uri .= $sep . $query;   
		}  


		// 处理POST请求数据  
		$data = '';  
		if ($method == 'POST' && !empty($this->vars)){  
			$data = Http::makeQuery($this->vars);   
		}  

		// 设置缺省头  
		$this->setHeader('User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1)');  
		if (!preg_match("/^[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}$/", $host)){  
			$this->setHeader("Host: ".$host);  
		}  
		if ($this->cookies != ''){  
			$this->setHeader("Cookie: ". $this->cookies);  
		}  
		$this->setHeader("Connection: Close");  
		//'Accept-Language: zh-cn',  
		//'Cache-Control: no-cache',          

		//构造头信息  
		$opts = array(  
			'http' => array(  
				'method'   => $method,  
				'timeout'  => $timeout,  
			)  
		);  
		if ($data != ''){  
			$opts['http']['content'] = $data;  
		}  
		$opts['http']['header'] = '';  
		foreach ($this->header as $h){  
			$opts['http']['header'] .= $h . "\r\n";  
		} 

		// 读取扩展设置选项  
		if (!empty($options)) {  
			isset($options['proxy']) ? $opts['http']['proxy'] = $options['proxy'] : '';           
			isset($options['max_redirects']) ? $opts['http']['max_redirects'] = $options['max_redirects'] : '';  
			isset($options['request_fulluri']) ? $opts['http']['request_fulluri'] = $options['request_fulluri'] : '';  
		}  

		// 发送数据返回  
		$context = stream_context_create($opts);  
		if (($buf = file_get_contents($this->uri, null, $context)) === false) {  
			throw new Exception(__CLASS__ .": file_get_contents(". $this->uri .") fail");  
		}
		return $buf;    
	}
}

